package com.java.auth.controller;

import com.java.auth.service.SysUserService;
import com.java.common.utils.R;
import com.java.model.system.SysUser;
import com.java.vo.system.SysUserQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/system/sysUser")
@Api(tags = "用户管理")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    @PreAuthorize("hasAuthority('bnt.sysUser.list')")
    @ApiOperation("条件分页查询用户")
    @GetMapping("/{current}/{limit}")
    public R selectListByPage(@PathVariable Long current, @PathVariable Long limit, SysUserQueryVo sysUserQueryVo){
        R r = sysUserService.select(current, limit, sysUserQueryVo);
        return r;
    }
    @PreAuthorize("hasAuthority('bnt.sysUser.list')")
    @ApiOperation("根据id查询用户")
    @GetMapping("/get/{id}")
    public R selectById(@PathVariable Long id){
         return sysUserService.selectById(id);
    }
    @PreAuthorize("hasAuthority('bnt.sysUser.add')")
    @PostMapping("/save")
    @ApiOperation("保存用户")
    public R save(@RequestBody SysUser sysUser){
        return sysUserService.saveUser(sysUser);
    }
    @PreAuthorize("hasAuthority('bnt.sysUser.update')")
    @PostMapping("/update")
    @ApiOperation("更新用户")
    public R update(@RequestBody SysUser sysUser){
        return sysUserService.update(sysUser);
    }
    @PreAuthorize("hasAuthority('bnt.sysUser.remove')")
    @DeleteMapping("/remove/{id}")
    @ApiOperation("根据id删除用户")
    public R deleteById(@PathVariable Long id){
        return sysUserService.deleteById(id);
    }
    @PreAuthorize("hasAuthority('bnt.sysUser.remove')")
    @DeleteMapping("/removeBatch")
    @ApiOperation("批量删除")
    public R deleteBatch(@RequestBody List<Long> ids){
        return sysUserService.deleteBatch(ids);
    }
    @ApiOperation("更新用户状态")
    @GetMapping("/updateStatus/{id}/{status}")
    public R updateStatus(@PathVariable Long id,@PathVariable Integer status){
        return sysUserService.updateStatus(id,status);
    }

}
